---
title: User Data Directory
sidebarTitle: User Data
description: Persist browser data between sessions
---
import { V3Banner } from '/snippets/v3-banner.mdx';

<V3Banner />

### User Data Directory

Persist browser data between sessions using a custom user data directory:

```typescript
import { Stagehand } from "@browserbasehq/stagehand";

// For Browserbase sessions
const stagehand = new Stagehand({
  env: "BROWSERBASE",
  browserbaseSessionCreateParams: {
    userDataDir: "/path/to/user/data/directory",
  },
});

// For Local sessions
const localStagehand = new Stagehand({
  env: "LOCAL",
  localBrowserLaunchOptions: {
    userDataDir: "./browser-data",
  },
});

await stagehand.init();
console.log("Session ID:", stagehand.sessionId);
```